<template>
	<l-tab v-model="tabActive" :list="tabList">
		<el-form ref="form" :model="form" label-width="100px">
			<el-form-item v-for="(item, i) in list" :key="i" :label="item.remark" :rules="{ required: true }">
				<el-input v-model.trim="item.dictValue" class="!md:w-[300px]"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" class="!w-[107px] !h-[40px]" @click="save('wx')">保存</el-button>
			</el-form-item>
		</el-form>
	</l-tab>
</template>

<script>
import { listData, updateDataList } from '@/api/system/dict/data';
export default {
	name: 'MessageConf',
	components: {},
	data() {
		return {
			tabActive: 0,
			tabList: ['短信配置'],
			form: {
				account: null,
				password: null,
				sendUrl: null,
			},
			list: [],
			oldData: {},
			rules: {
				account: [{ required: true, message: '请填写账户', trigger: 'blur' }],
				password: [{ required: true, message: '请填写MD5格式的密码', trigger: 'blur' }],
				sendUrl: [{ required: true, message: '请填写请求地址', trigger: 'blur' }],
			},
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				dictName: undefined,
				dictType: undefined,
				status: undefined,
			},
			requestParam: {
				name: 'SMSConfig',
			},
		};
	},

	created() {
		this.getList();
	},
	methods: {
		getList() {
			this.queryParams.dictType = 'SMSaspx';
			listData(this.queryParams).then((res) => {
				this.list = res.rows;
			});
		},
		save() {
			let dataList = this.list;
			for (let item in dataList) {
				if (dataList.hasOwnProperty(item)) {
					if (!dataList[item].dictValue) {
						this.$message.error(dataList[item].remark + '不能为空');
						return;
					}
				} else {
					return;
				}
			}
			updateDataList(dataList).then(() => {
				this.$message.success('编辑成功');
				this.getList();
			});
		},
	},
};
</script>

<style scoped lang="scss">
.conf {
	::v-deep .el-card__body {
		height: 100vh;
	}
	&__left {
		border-right: 1px solid #f3f4f7;
		.items {
			height: 48px;
			border-radius: 4px;
			background-color: rgba(76, 89, 198, 0.3);
			line-height: 48px;
			text-align: center;
			font-weight: bold;
			font-size: 12px;
			color: #4c59c6;
			border: 1px solid #4c59c6;
		}
	}
}
</style>
